package org.jeecg.common.util;

import com.alibaba.fastjson.JSON;
import org.jeecg.common.exception.RestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

/**
 * 江苏如东化工园区Hppt上传接口
 * @author wangk
 *
 */
@Service
public class JstlHttpUpload {
	private static final Logger LOG = LoggerFactory
            .getLogger(JstlHttpUpload.class);



	/**
	  *  通亮真趣url调用
	 * @param url
	 * @param data
	 */
	public String seteExecute(String url ,String data,Map<String,String> headerMap) {
		try {
			LOG.info("通量真趣接口入参：[url：{}；内容：{}；头部内容：{}；]", url, data,JSON.toJSONString(headerMap));
			String postHeaderParam = null;
			if(url.contains("https")) {
				postHeaderParam =  OkHttpRequest.postSSLParam(url, data,headerMap);
			}else {
				postHeaderParam = OkHttpRequest.postHeaderParam(url, data, headerMap);
			}

			LOG.info("通量真趣接口入参：[返回值：{}；]", postHeaderParam);
			return postHeaderParam;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RestException("上传错误");
		}

	}
	/**
	  *  通亮 科讯url调用
	 * @param url
	 * @param data
	 */
	public String setkxPostForm(String url ,Map<String,String> bodyMap) {
		try {
			LOG.info("通量科讯接口入参：[url：{}；内容：{}；]", url,JSON.toJSONString(bodyMap));
			String postHeaderParam = OkHttpRequest.postForm(url, bodyMap);
			LOG.info("通量科讯接口入参：[返回值：{}；]", postHeaderParam);
			return postHeaderParam;
		} catch (IOException e) {
			e.printStackTrace();
			throw new RestException("上传错误");
		}

	}
	/**
	  *  通亮 航飞  post url调用
	 * @param url
	 * @param data
	 */
	public String setPostHangfei(String url ,String data) {
		try {
			LOG.info("接口入参：[url：{}；内容：{}]", url, data);
			String postHeaderParam = null;
			postHeaderParam =  OkHttpRequest.post(url, data);
			LOG.info("接口入参：[返回值：{}；]", postHeaderParam);
			return postHeaderParam;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RestException("上传错误");
		}

	}


	/**
	  *  通亮 航飞  get url调用
	 * @param url
	 * @param data
	 */
	public String setGetHangfei(String url ,Map<String,String> body,Map<String,String> header) {
		try {
			LOG.info("通量派尔科接口入参：[url：{}；内容：{}]", url, JSON.toJSONString(body));
			String postHeaderParam = null;
			postHeaderParam =  OkHttpRequest.getHeadForm(url, header,body);
			LOG.info("通量派尔科接口入参：[返回值：{}；]", postHeaderParam);
			return postHeaderParam;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RestException("上传错误");
		}

	}
	/**
	  *  通亮 航飞  get url调用
	 * @param url
	 * @param data
	 */
	public String setDeleteHangfei(String url ,Map<String,String> body,Map<String,String> header) {
		try {
			LOG.info("通量派尔科接口入参：[url：{}；内容：{}]", url, JSON.toJSONString(body));
			String postHeaderParam = null;
			postHeaderParam =  OkHttpRequest.getDeleteForm(url, header,body);
			LOG.info("通量派尔科接口入参：[返回值：{}；]", postHeaderParam);
			return postHeaderParam;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RestException("上传错误");
		}

	}
	/**
	  *  通亮 航飞  post 带头部调用
	 * @param url
	 * @param data
	 */
	public String setPostHeaderHangfei(String url ,String body,Map<String,String> header) {
		try {
			LOG.info("通量派尔科接口入参：[url：{}；内容：{}]", url, body);
			String postHeaderParam = null;
			postHeaderParam =  OkHttpRequest.postHeaderParam(url, body,header);
			LOG.info("通量派尔科接口入参：[返回值：{}；]", postHeaderParam);
			return postHeaderParam;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RestException("上传错误");
		}

	}


}
